package com.ctshk.sapp.season.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.enums.SeasonType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.season.dto.DepartCalendarDTO;
import com.ctshk.rpc.season.dto.FixedSeasonDetailsDTO;
import com.ctshk.rpc.season.dto.FixedSeasonProductPageDTO;
import com.ctshk.rpc.season.req.*;
import com.ctshk.rpc.season.service.ISeasonFixedProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 套票-固定套票产品基本信息表 前端控制器
 * </p>
 *
 * @author 杨林
 * @since 2021-03-08
 */
@Api(value = "资源套票-固定套票产品基本信息", tags = "资源套票-固定套票产品基本信息")
@RestController
@RequestMapping("/season-fixed-product")
@Slf4j
public class SeasonFixedProductController extends BaseController {

    @DubboReference
    private ISeasonFixedProductService fixedProductService;

    @ApiOperation(value = "资源中心-固定套票-产品分页查询列表", notes = "资源中心-固定套票-产品分页查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.QUERY, operTitle = "固定套票分页查询列表", operDesc = "固定套票分页查询列表")
    @PostMapping("/list")
    public Result<PageResponse<FixedSeasonProductPageDTO>> list(@RequestBody SearchFixedProductReq searchFixedProductReq) {
        TokenUser user = getCurrentUser(getRequest());
        PageResponse<FixedSeasonProductPageDTO> response = fixedProductService.searchSeasonFixedProduct(searchFixedProductReq, user);
        return Result.success(response);
    }

    @ApiOperation(value = "添加固定套票基本信息", notes = "添加固定套票基本信息")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.ADD, operTitle = "添加固定套票基本信息", operDesc = "添加固定基本信息")
    @PostMapping("/saveBase")
    public Result saveFixedSeason(@RequestBody @Valid SeasonFixedBaseReq seasonFixedBaseReq) {
        log.info("进入添加固定套票基本信息----------->,{}",seasonFixedBaseReq);
        TokenUser user = getCurrentUser(getRequest());
        //保存固定套票基本信息
        return fixedProductService.addSeasonFixedProduct(user, seasonFixedBaseReq);

    }

    @ApiOperation(value = "添加固定套票补充信息", notes = "添加固定套票补充信息")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.ADD, operTitle = "添加固定套票补充信息", operDesc = "添加固定套票补充信息")
    @PostMapping("/saveReplenish")
    public Result saveFixedSeasonProductReplenish(@RequestBody SeasonFixedReplenishReq seasonFixedReplenishReq) {
        //保存固定套票补充信息信息
        return fixedProductService.addSeasonFixedProductReplenish(seasonFixedReplenishReq);
    }

    @ApiOperation(value = "固定套票详情信息", notes = "固定套票详情信息")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.QUERY, operTitle = "固定套票详情信息", operDesc = "固定套票详情信息")
    @PostMapping("/details")
    public Result<FixedSeasonDetailsDTO> getFixedSeasonProductDetails(@RequestBody SeasonFixedReplenishReq req) {
        TokenUser user = getCurrentUser(getRequest());
        //获取固定套票 详情 信息
        return fixedProductService.getFixedSeasonProductDetails(user, req.getProductId());
    }

    @ApiOperation(value = "检查固定套票产品编号是否重复", notes = "检查固定套票产品编号是否重复")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.QUERY, operTitle = "查询固定套票产品编号是否重复", operDesc = "查询固定套票产品编号是否重复")
    @PostMapping("/checkProductCode")
    public Result checkFixedSeasonProductCode(String code) {
        TokenUser user = getCurrentUser(getRequest());
        //保存固定套票基本信息
        return fixedProductService.checkFixedSeasonProductCode(user, code);

    }


    @ApiOperation(value = "资源中心-固定套票-操作项", notes = "操作固定套餐产品")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.UPDATE, operTitle = "查询固定套票产品编号是否重复", operDesc = "查询固定套票产品编号是否重复")
    @PostMapping("/setProductState")
    public Result updateFixedSeasonProductState(@RequestBody @Valid SeasonFixedProductStateReq req) {
        TokenUser user = getCurrentUser(getRequest());
        return fixedProductService.updateFixedSeasonProductState(user, req);
    }

    @ApiOperation(value = "资源中心-固定套票-编辑套票", notes = "编辑固定套餐产品")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.UPDATE, operTitle = "编辑固定套餐产品", operDesc = "编辑固定套餐产品")
    @PostMapping("/update")
    public Result updateFixedSeason(@RequestBody @Valid SeasonFixedReq req) {
        TokenUser user = getCurrentUser(getRequest());
        return fixedProductService.updateFixedSeason(user, req);
    }


    @ApiOperation(value = "资源中心-固定套票-审核", notes = "资源中心 审核固定套票")
    @PostMapping("/flowCheck")
    public Result flowCheckFixedSeason(@RequestBody @Valid FlowCheckFixedSeasonReq req) {
        TokenUser user = getCurrentUser(getRequest());
        return fixedProductService.flowCheckFixedSeason(user, req);
    }


    @ApiOperation(value = "资源中心-套票详情-出行日历", notes = "资源中心-套票详情-出行日历")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.QUERY, operTitle = "资源中心-套票详情-出行日历", operDesc = "资源中心-套票详情-出行日历")
    @PostMapping("/getDepartCalendar")
    public Result<List<DepartCalendarDTO>> getDepartCalendarDTOList(@RequestBody @Valid DepartCalendarReq req) {
        return Result.success(fixedProductService.getDepartCalendarDTOList(req.getProductId(), req.getStartDate(), req.getEndDate(), null, SeasonType.OFFLINE_SELF_CHANNEL_TYPE.getCode(), null));
    }


    /* @MethodName: 获取使用推广码 的固定套票产品
     * @Description: TODO
     * @Param:
     * @Return:
     * @Author: 杨林
     * @Date:2021/4/21 17:51
     **/
    @ApiOperation(value = "获取使用推广码的套票产品", notes = "获取使用推广码的套票产品", tags = "获取使用推广码的套票产品")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.QUERY, operTitle = "获取使用推广码的套票产品", operDesc = "套票-使用推广码的套票产品")
    @PostMapping("/getEmployCouponCodeSeasonList")
    public Result<PageResponse<FixedSeasonProductPageDTO>> getEmployCouponCodeSeason(@RequestBody SearchFixedProductReq req) {
        TokenUser user = getCurrentUser(getRequest());
        return Result.success(fixedProductService.getEmployCouponCodeSeason(req, user));
    }


    /* @MethodName: 通过ids 获取套票信息
     * @Description: TODO
     * @Param:
     * @Return:
     * @Author: 杨林
     * @Date:2021/4/22 16:07
     **/
    @ApiOperation(value = "获取使用推广码的套票产品", notes = "获取使用推广码的套票产品", tags = "获取使用推广码的套票产品")
    @OperationLogAnnotation(operModul = OperationLogModel.VISA, operType = OperationLogType.ADD, operTitle = "获取使用推广码的套票产品", operDesc = "套票-使用推广码的套票产品")
    @GetMapping("/getSeasonProductByIds/{ids}")
    public Result<List<FixedSeasonProductPageDTO>> getSeasonProduct(@PathVariable("ids") String ids) {
        return Result.success(fixedProductService.getSeasonProductList(ids));
    }
}
